<?php

namespace app\common\validate;

use think\Validate;

class Member extends Validate
{
    protected $rule = [
//        'password' => 'require|length:5,20|alphaDash',
        'phone' => ['regex'=>'/^1[3|4|5|7|8][0-9]\d{4,8}$/i'],
        'password' => 'require|length:5,21|regex:/^(?=.*\d)(?=.*[a-zA-Z]).{6,20}$/',
        'code' => 'require',
        'safe_password' => ['regex'=>'/^[0-9]{6}$/i', 'require']
    ];

    protected $message = [
        'phone.regex'=>  400026,
        'phone.unique'=>  400114,
        'phone.require'=>  400020,
        'password.require' =>  400021,
        'password.length' =>  400113,
        'password.regex' =>  400115,
        'code.require' => 400006,
        'safe_password.regex' =>  400126,
        'safe_password.require' =>  400127,
    ];

    protected $scene = [
        'add'   =>  ['phone' => ['regex'=>'/^1[3|4|5|7|8][0-9]\d{8}$/i', 'unique' => 'member', 'require'] , 'password',  'code'],
        'retrieve_password'   =>  ['phone' => ['regex'=>'/^1[3|4|5|7|8][0-9]\d{8}$/i', 'require'] , 'password', 'code'],
        'password'   =>  ['password'],
        'safe_password'   =>  ['safe_password'],
        'phone'   =>  ['phone' => ['regex'=>'/^1[3|4|5|7|8][0-9]\d{8}$/i']],
        'update_phone'   =>  ['phone' => ['regex'=>'/^1[3|4|5|7|8][0-9]\d{8}$/i', 'unique' => 'member']]
    ];
}